package com.special.controller;

import com.special.model.User;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;

/**
 * @Description: 得到容器测试
 * @author: LiuYC
 * @date: 2021年04月23日 15:53
 * <p>
 * •无参构造函数创建对象
 * •带参数的构造函数创建对象
 * •工厂创建对象
 * –静态方法创建对象
 * –非静态方法创建对象
 */
@ContextConfiguration
public class GetUserController {
    public static void test1() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        User user = (User) ac.getBean("user");
        System.out.println(user);
    }

    public static void test2() {
        ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        User user = (User) ac.getBean("user");
        System.out.println(user);
    }

    public  static void test3() {
        // 创建容器对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        UserAction userAction = (UserAction) ac.getBean("userAction");
        userAction.execute();
    }

    public static void main(String[] args) {


//        GetUserController.test1();

//        GetUserController.test2();
        GetUserController.test3();
    }
}
